﻿/******************************************************************************
* File description: AnimationLayout3.qml
* Function: 转靶动画模块（包含摄像头、 按钮等布局）
* Current Version: 1.0.0
* Author: JNN
* Date: 2025-07-01
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtGraphicalEffects 1.12

import "../components"
import "../pageComponents"
import "../animation/shiftingAnimation"
import "../camera"
import "../promptBox"

Rectangle{
    id: root
    height: parent.height
    width: parent.width
    radius: 5*dp
    clip: true
    color: "#E0E6E9"

    property int showMode: 0        // 0放大显示动画 1放大显示摄像头
    property bool editable: (gExpIsRunning===0 || gExpIsFailure&1==1) && gConnectStatus===true

    // 右上角的尺码
    property real graphWidth: Math.max(Math.min(width, height*1.5)*0.17 * 1.3, 200*dp)
    property real graphHeight: Math.max(Math.min(width, height*1.5)*0.17, 140*dp)

    property real boxPadding: 20*dp

    signal fullScreen()



    Text{
        x: 20*dp; y: 20*dp
        font.bold: true
        text: qsTr("实验流程")
        font.pixelSize: config.fontsize_1
        z: 100
    }

    onVisibleChanged: {
        if(visible){
            canvas_shifting.startAnimation()
        }else{
            canvas_shifting.stopAnimation()
        }
    }
    ShiftingCanvas{
        id: canvas_shifting
        anchors.fill: showMode === 0 ? fakeCanvasAnchors : area_corner
        z: showMode
    }
    Item{
        id: fakeCanvasAnchors       // 图画小了，改了一下画布的尺码
        height: root.height * 1
        width: root.width * 1.02
        x: root.width * 0.1
    }
    CameraDisplay{
        cameraName: "CameraShifting"
        cameraId: gStateCamera.cameraId_1
        anchors.fill: showMode === 1 ? root : area_corner
        z: 1-showMode
    }
    MouseArea{
        id: area_corner
        height: graphHeight; width: graphWidth
        y: boxPadding; x: parent.width - width - boxPadding
        cursorShape: Qt.PointingHandCursor
        hoverEnabled: true
        onEntered: { toolTip_doubleClicked.visible = true }
        onExited: { toolTip_doubleClicked.visible = false }
        onDoubleClicked: {
            showMode = 1 - showMode
        }
        CustomTooltip{
            id: toolTip_doubleClicked
            text: "双击放大显示"
        }
    }
    Column{
        x: area_corner.x
        y: area_corner.y + area_corner.height + 8*dp
        width: 210*dp
        spacing: 2*dp
        // 暂停
        TimerCard_pause{
            id: pauseModule
            z: 100
            width: area_corner.width
        }
        // 等待
        TimerCard_wait{
            id: waitModule
            z: 100
            width: area_corner.width
        }
        // 气泵
        TimerCard_air{
            id: timerCard_air
            width: area_corner.width
        }
        // 水泵
        TimerCard_water{
            id: timerCard_water
            width: area_corner.width
        }
        TimerCard_failure{
            id: timerCard_failure
            width: area_corner.width
            onClicked: {
                box_failureInfo2.show()
            }
        }
    }

    // 右下角的按钮区域
    Column{
        spacing: 16*dp
        x: parent.width - width - 20*dp
        y: parent.height - height - 20*dp
        CircleButton{       // 全屏
            icon: "qrc:/picture/animation/fullScreen.png"
            icon_hover: "qrc:/picture/animation/fullScreen_h.png"
            onClicked: {
                root.fullScreen()
            }
            CustomTooltip{
                text: "全屏"
                visible: parent.isHovered
            }
        }
        CircleButton{       // 按钮
            id: button_showButtonList
            icon: "qrc:/picture/animation/showButtonList.png"
            icon_hover: "qrc:/picture/animation/showButtonList_h.png"
            property bool showButtonList: false
            onClicked: {
                showButtonList = !showButtonList
            }
            CustomTooltip{
                text: "操作按钮栏"
                visible: parent.isHovered
            }
        }
        z: 1
    }
    Item{    // 可收缩式按钮
        id: layout_button
        x: 40*dp;   width: parent.width - 2*x
        y: parent.height - 20*dp - height;     height: 50*dp
        clip: true
        Rectangle{
            id: button_area
            radius: 25*dp
            height: 50*dp
            width: row_button.width + 120*dp
            state: button_showButtonList.showButtonList ? "show" : "hide"
            states: [
                State {
                    name: "show"
                    PropertyChanges {
                        target: button_area
                        x: layout_button.width- width + 40*dp
                        opacity: 1
                    }
                },
                State {
                    name: "hide"
                    PropertyChanges {
                        target: button_area
                        x: layout_button.width
                        opacity: 0
                    }
                }
            ]
            transitions: [
                Transition {
                    from: "show"
                    to: "hide"
                    NumberAnimation{
                        properties: "x"
                        duration: 200
                        easing.type: Easing.InOutQuad
                    }NumberAnimation{
                        properties: "opacity"
                        duration: 200
                        easing.type: Easing.InOutQuad
                    }
                },
                Transition {
                    from: "hide"
                    to: "show"
                    NumberAnimation{
                        properties: "x"
                        duration: 200
                        easing.type: Easing.InOutQuad
                    }NumberAnimation{
                        properties: "opacity"
                        duration: 200
                        easing.type: Easing.InOutQuad
                    }
                }
            ]
            Row{
                id: row_button
                anchors.verticalCenter: parent.verticalCenter
                x: 25*dp
                height: 36*dp
                spacing: 8*dp

                CustomButton{
                    id: button_cap1
                    title: "开盖"
                    autoWidth: true
                    height: 36*dp
                    enabled: root.editable
                    defaultMode1: true
                    onClicked: {
                        gStateOp.openPopup("29", [])
                        CommunicationMethod.stepOperatingSimulation("3","4",["开盖流程"])
                        CAnimationShifting.openCap()
                    }
                }
                CustomButton{
                    id: button_cap2
                    title: "关盖"
                    autoWidth: true
                    height: 36*dp
                    enabled: root.editable
                    defaultMode1: true
                    onClicked: {
                        gStateOp.openPopup("29", [])
                        CommunicationMethod.stepOperatingSimulation("3","4",["关盖流程"])
                        CAnimationShifting.closeCap()
                    }
                }
//                CustomButton{
//                    id: button_rotateCap_1
//                    title: "旋盖-开"
//                    autoWidth: true
//                    height: 36*dp
//                    enabled: root.editable
//                    defaultMode1: true
//                    onClicked: {
//                        gStateOp.openPopup("29", [])
//                        CommunicationMethod.stepOperatingSimulation("3","4",["开盖"])
////                        CAnimationShifting.closeCap()
//                    }
//                }
//                CustomButton{
//                    id: button_rotateCap_2
//                    title: "旋盖-关"
//                    autoWidth: true
//                    height: 36*dp
//                    enabled: root.editable
//                    defaultMode1: true
//                    onClicked: {
//                        gStateOp.openPopup("29", [])
//                        CommunicationMethod.stepOperatingSimulation("3","4",["关盖"])
////                        CAnimationShifting.closeCap()
//                    }
//                }
//                CustomButton{
//                    id: button_clamCap_1
//                    title: "旋盖夹爪-夹"
//                    autoWidth: true
//                    height: 36*dp
//                    enabled: root.editable
//                    defaultMode1: true
//                    onClicked: {
//                        gStateOp.openPopup("29", [])
//                        CommunicationMethod.stepOperatingSimulation("3","11",["夹紧"])
////                        CAnimationShifting.closeCap()
//                    }
//                }
//                CustomButton{
//                    id: button_clamCap_2
//                    title: "旋盖夹爪-松"
//                    autoWidth: true
//                    height: 36*dp
//                    enabled: root.editable
//                    defaultMode1: true
//                    onClicked: {
//                        gStateOp.openPopup("29", [])
//                        CommunicationMethod.stepOperatingSimulation("3","11",["松开"])
////                        CAnimationShifting.closeCap()
//                    }
//                }
                CustomButton{
                    id: button_takeTarget1
                    title: "靶材罐-取靶"
                    autoWidth: true
                    height: 36*dp
                    enabled: root.editable
                    defaultMode1: true
                    onClicked: {
                        gStateOp.openPopup("2A", [])
                        CommunicationMethod.stepOperatingSimulation("3","2",["取靶","靶材罐", ""])
                        CAnimationShifting.takeTarget()
                    }
                }
                CustomButton{
                    id: button_takeTarget2
                    title: "靶材罐-放靶"
                    autoWidth: true
                    height: 36*dp
                    enabled: root.editable
                    defaultMode1: true
                    onClicked: {
                        gStateOp.openPopup("2A", [])
                        CommunicationMethod.stepOperatingSimulation("3","2",["放靶","溶靶瓶", ""])
                        CAnimationShifting.placeTarget()
                    }
                }
//                CustomButton{
//                    id: button_takeTarget4
//                    title: "活检-取靶"
//                    autoWidth: true
//                    height: 36*dp
//                    visible: gHasRadioBar === 1
//                    enabled: root.editable
//                    defaultMode1: true
//                    onClicked: {
//                        gStateOp.openPopup("2A", [])
//                        CommunicationMethod.stepOperatingSimulation("3","2",["取靶","活性检测位", ""])
//                        CAnimationShifting.moveToRadio()
//                    }
//                }
//                CustomButton{
//                    id: button_takeTarget3
//                    title: "活检-放靶"
//                    autoWidth: true
//                    height: 36*dp
//                    visible: gHasRadioBar === 1
//                    enabled: root.editable
//                    defaultMode1: true
//                    onClicked: {
//                        gStateOp.openPopup("2A", [])
//                        CommunicationMethod.stepOperatingSimulation("3","2",["放靶","活性检测位", ""])
//                        CAnimationShifting.moveToRadio()
//                    }
//                }
                CustomButton{
                    id: button_upHuoJian
                    title: "活检-上移"
                    autoWidth: true
                    height: 36*dp
                    visible: gHasRadioBar === 1
                    enabled: root.editable
                    defaultMode1: true
                    onClicked: {
                        gStateOp.openPopup("2A", [])
                        CommunicationMethod.stepOperatingSimulation("3","10",["上移"])
                        CAnimationShifting.upRadioBar()
                    }
                }
                CustomButton{
                    id: button_downHuoJian
                    title: "活检-下移"
                    autoWidth: true
                    height: 36*dp
                    visible: gHasRadioBar === 1
                    enabled: root.editable
                    defaultMode1: true
                    onClicked: {
                        gStateOp.openPopup("2A", [])
                        CommunicationMethod.stepOperatingSimulation("3","10",["下移"])
                        CAnimationShifting.downRadioBar()
                    }
                }
                CustomButton{
                    id: button_claw1
                    title: "夹爪松开"
                    autoWidth: true
                    height: 36*dp
                    enabled: root.editable
                    defaultMode1: true
                    onClicked: {
                        gStateOp.openPopup("2B", [])
                        CommunicationMethod.stepOperatingSimulation("3","3",["松开"])
                        CAnimationShifting.openClamp()
                    }
                }
                CustomButton{
                    id: button_claw2
                    title: "夹爪夹紧"
                    autoWidth: true
                    height: 36*dp
                    enabled: root.editable
                    defaultMode1: true
                    onClicked: {
                        gStateOp.openPopup("2B", [])
                        CommunicationMethod.stepOperatingSimulation("3","3",["夹紧"])
                        CAnimationShifting.closeClamp()
                    }
                }
                CustomButton{
                    id: button_baffle1
                    title: "挡板关"
                    autoWidth: true
                    height: 36*dp
                    enabled: root.editable
                    defaultMode1: true
                    onClicked: {
                        gStateOp.openPopup("20", [])
                        CommunicationMethod.stepOperatingSimulation("3","1",["关闭"])
                        CAnimationShifting.pushBaffle()
                    }
                }
                CustomButton{
                    id: button_baffle2
                    title: "挡板开"
                    autoWidth: true
                    height: 36*dp
                    enabled: root.editable
                    defaultMode1: true
                    onClicked: {
                        gStateOp.openPopup("20", [])
                        CommunicationMethod.stepOperatingSimulation("3","1",["打开"])
                        CAnimationShifting.pullBaffle()
                    }
                }
                CustomButton{
                    id: button_pPump
                    title: "转液"
                    autoWidth: true
                    height: 36*dp
                    enabled: root.editable
                    defaultMode1: true
                    onClicked: {
                        box_rudongbeng.minSpeed = 100
                        box_rudongbeng.maxSpeed = 700
                        box_rudongbeng.show()
                    }
                }

//                CustomButton{
//                    id: button_pPump_l
//                    title: "蠕动泵吸"
//                    autoWidth: true
//                    height: 36*dp
//                    enabled: root.editable
//                    defaultMode1: true
//                    onClicked: {
//                        gStateOp.openPopup("2C", [])
//                        CommunicationMethod.stepOperatingSimulation("3","6",["吸液","20"])
//                        CAnimationShifting.setPPumpState(-1);
//                    }
//                }
//                CustomButton{
//                    id: button_pPump_r
//                    title: "蠕动泵打"
//                    autoWidth: true
//                    height: 36*dp
//                    enabled: root.editable
//                    defaultMode1: true
//                    onClicked: {
//                        gStateOp.openPopup("2C", [])
//                        CommunicationMethod.stepOperatingSimulation("3","6",["打液","20"])
//                        CAnimationShifting.setPPumpState(1);
//                    }
//                }
//                CustomButton{
//                    id: button_pPump_close
//                    title: "蠕动泵关"
//                    autoWidth: true
//                    height: 36*dp
//                    enabled: root.editable
//                    defaultMode1: true
//                    onClicked: {
//                        gStateOp.openPopup("2C", [])
//                        CommunicationMethod.stepOperatingSimulation("3","6",["关闭","20"])
//                        CAnimationShifting.setPPumpState(0);
//                    }
//                }
            }
        }
    }

    BoxRuDongBeng{
        id: box_rudongbeng
    }

}
